=== Handlebar support [[handlebars]]

https://github.com/jknack/handlebars.java[The Handlebars templates] may be used for templating values in Exam commands.

Exam provides following built-in https://github.com/jknack/handlebars.java#helpers[helpers] groups:

Date helpers:: [pre language-handlebars e-echo=dateHelpers]`{empty}`
Data matcher helpers:: [pre language-handlebars e-echo=matcherHelpers]`{empty}`
Misc helpers:: [pre language-handlebars e-echo=miscHelpers]`{empty}`

.Data types matchers:
[source,asciidoc]
--
include::core-handlebar.adoc[tags=hb-t]
--

====
//tag::hb-t[]
[.given]
.`dataJson`:
[source,json,e-set=dataJson]
{
  "string": "some string",
  "number": 123,
  "bool": true,
  "ignore": "anything 123",
  "regex": "123"
}

[.then]
.`dataJson` matches:
[source,json,e-eq-json=#dataJson]
{
  "string": "{{string}}",
  "number": "{{number}}",
  "bool": "{{bool}}",
  "ignore": "{{ignore}}",
  "regex": "{{regex '\\d+'}}"
}

//end::hb-t[]
====

.Check with matcher and set actual to variable:
[source,asciidoc]
--
include::core-handlebar.adoc[tags=hb-m-s]
--

====
//tag::hb-m-s[]
.Check and set
[%header, e-execute="#r = lowercase(#param)"]
|===
|[e-set=param]#Param# |[e-eq=#r.text]#Text#

|ABC |{{string}}>>str1
|DEF |{{ignore}}>>str2
|===
Actual value is matched and set to variable: str1 = [e-eq=#str1]`abc`, str2 = [e-eq=#str2]`def`
//end::hb-m-s[]
====

.Date/time matchers:
[source,asciidoc]
----
include::core-handlebar.adoc[tags=hb-dt]
----

====
//tag::hb-dt[]
[.given]
.`dtJson`:
[source,json,e-set=dtJson]
--
{
  "customFormat": "{{format (at) "yyyy/MM/dd'T'HH:mm.ss"}}",
  "isoDate": "{{isoDate (at)}}",
  "iso": "{{iso (at)}}",

  "customFormatAndWithinNow": "{{format (at) "yyyy/MM/dd'T'HH:mm.ss"}}",
  "isoDateAndWithinNow": "{{isoDate (at)}}",
  "isoAndWithinNow": "{{iso (at)}}",

  "customFormatAndWithinSpecifiedDate": "{{format (at) "yyyy/MM/dd'T'HH:mm.ss"}}",
  "isoDateAndWithinSpecifiedDate": "{{isoDate (at)}}",
  "isoAndWithinSpecifiedDate": "{{iso (at)}}",

  "afterSpecifiedDate": "{{iso (at)}}",
  "beforeSpecifiedDate": "{{iso (at)}}"
}
--
[.then]
.`dtJson` matches:
[source,json,e-eq=#dtJson,e-verifier=json]
--
{
"customFormat": "{{formattedAs 'yyyy/MM/dd\'T\'HH:mm.ss'}}",
"isoDate": "{{isoDate}}",
"iso": "{{iso}}",

"customFormatAndWithinNow": "{{formattedAndWithin 'yyyy/MM/dd\'T\'HH:mm.ss' '25s'}}",
"isoDateAndWithinNow": "{{isoDate '1d'}}",
"isoAndWithinNow": "{{iso '25s'}}",

"customFormatAndWithinSpecifiedDate": "{{formattedAndWithin 'yyyy/MM/dd\'T\'HH:mm.ss' '25s' (now)}}",
"isoDateAndWithinSpecifiedDate": "{{isoDate '1d' (now)}}",
"isoAndWithinSpecifiedDate": "{{iso '25s' (now)}}",

"afterSpecifiedDate": "{{after (at '-1h')}}",
"beforeSpecifiedDate": "{{before (at '+1h')}}"
}
--
//end::hb-dt[]
====
